<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="/WEB-INF/quik_function.tld" prefix="qu"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>咨客_结帐</title>
		<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/default/easyui.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/icon.css" />" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.2.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/util.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/zDialog/zDrag.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/zDialog/zDialog.js" />"></script>
		<script type="text/javascript">
			//清空
			function onReset(){
				$("#tokenNo").val('');
				$("#roomNo").val('');
			}
			
			//返回
			function onReturn(){
				location.href = "${pageContext.request.contextPath}/consultToken/tokenList";
			}
			
			//全选
			function checkAll(chx){				
				if(chx.checked){
					$("input[name='billingNoBox']").attr("checked",true);
				}else
					$("input[name='billingNoBox']").attr("checked",false);
			}
			
			//结帐
			function onPay(){
				var flag = false;
				var chx = document.getElementsByName("billingNoBox");
				for(var i = 0; i < chx.length; i++){
					if(chx[i].checked){
						flag = true;
						break;
					}
				}
				
				if(flag)
					$("#calcForm").submit();
				else
					$.messager.alert('警告', "请选择需结帐帐单!");
			}
			
			//查询
			function onQuery(){
				$.ajax({
					url:'queryPayBilling',
					data:{'tokenNo':$.trim($("#tokenNo").val()),
						  'roomNo':$.trim($("#roomNo").val())},
					type:'post',
					dataType:'json',
					async:false,
					cache:false,
					success:function(data){
						if(data.result == 'success'){
							onCancelTable("tokenTable");
							if(data.billingSize > 0){
								$(data.billingList).each(function(){
									var rownum = $("#tokenTable tr").length;
									var row = "<tr>";
									row += "<td style='border: 1px solid #7F9DB9;font-weight: bold;'><input type='checkBox' name='billingNoBox' " +
									      "value='" + this['billing_no'] + "' /></td>"
									row += "<td style='border: 1px solid #7F9DB9;'>" + rownum + "</td>";
									row += "<td style='border: 1px solid #7F9DB9;'>";
									if(this['if_master'] == '${master}')
										row += "主帐单";
									else
										row += "关联帐单";
									row += "</td>";
									row += "<td style='border: 1px solid #7F9DB9;'>" + this['billing_no'] + "</td>";
									row += "</tr>";
									
									$("#tokenTable").append(row);
								});
							}else{
								$("#tokenTable").append("<tr><td colspan='4' style='border: 1px solid #7F9DB9;'>无帐单</td></tr>");
							}
						}else{
							$.messager.alert('操作结果', "系统繁忙!");
						}
					}
				});
			}
			
			function onCancelTable(id){
				var row = $("#" + id + " tr").length;
				
				for(var i = row - 1; i >= 1; i--){					
					$("#" + id).find("tr").eq(i).remove();
				}
			}
		</script>
	</head>
	
	<body>
		<c:import url="/WEB-INF/resources/common/consult_header.jsp" />
		
		<h1>结帐</h1>
		
		<div style="float:left; width:1000px;margin-right: 15px;">
			<div>				
				<div style="max-height:30px;margin-left: 30px; padding-bottom:10px; border-bottom: 1px solid #000">
					手牌编号：
					<input class="easyui-validatebox" style="width:150px;" type="text"  name="tokenNo" id="tokenNo" />
					&nbsp;&nbsp;&nbsp;&nbsp;
					房间编号：
					<input class="easyui-validatebox" style="width:150px;" type="text"  name="roomNo" id="roomNo" />
	    			<a href="javascript:void(0)" class="easyui-linkbutton" style="margin-left: 80px;" onclick="onQuery()">查询</a>
	    			&nbsp;&nbsp;
	    			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onReset()">清空</a>
	    			&nbsp;&nbsp;
	    			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onReturn()">返回</a>
				</div>
			</div>
			
			<form name="calcForm" id="calcForm" action="calcBilling" method="post">
			<div id="tokenDIV" style="margin-top: 5px; margin-left:30px; display: block;">
				<h1>帐单列表</h1>
				<table id="tokenTable" style="border-collapse: collapse;width:350px;text-align: center;">
					<tr>
						<td style="border: 1px solid #7F9DB9;font-weight: bold;">
							<input type="checkbox" onclick="checkAll(this)"/>
						</td>
						<td style="border: 1px solid #7F9DB9;font-weight: bold;">序号</td>
						<td style="border: 1px solid #7F9DB9;font-weight: bold;">帐单类型</td>
						<td style="border: 1px solid #7F9DB9;font-weight: bold;">帐单编号</td>
					</tr>
					<c:if test="${fn:length(billingList) == 0}">
						<tr><td colspan="3" style="border: 1px solid #7F9DB9;font-weight: bold;text-align: center;">无未结帐帐单</td></tr>
					</c:if>
					<c:forEach var="billing" items="${billingList}" varStatus="status">
						<tr>
							<td style="border: 1px solid #7F9DB9;font-weight: bold;">
								<input type="checkBox" name="billingNoBox" value="${billing.billing_no}"/>
							</td>
							<td style="border: 1px solid #7F9DB9;font-weight: bold;">${status.index + 1}</td>
							<td style="border: 1px solid #7F9DB9;font-weight: bold;">
								<c:choose>
									<c:when test="${billing.if_master == master}">主帐单</c:when>
									<c:otherwise>关联帐单</c:otherwise>
								</c:choose>
							</td>
							<td style="border: 1px solid #7F9DB9;font-weight: bold;">${billing.billing_no}</td>
						</tr>
					</c:forEach>
				</table>
			</div>
			
			<div style="margin-top: 10px; margin-left:30px; width: 1000px; text-align: center;" >
				<input type="button" name="payBtn" id="payBtn" value="结帐" onclick="onPay()">
			</div>
			</form>
		</div>
		
	</body>
</html> 